﻿using DailyApp.WPF.DTOs;
using DailyApp.WPF.Service;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace DailyApp.WPF.ViewModels.DialogViewModels
{
    internal class AddMemoUCViewModel : BindableBase, IDialogHostAware
    {
        #region 委托命令

        public DelegateCommand SaveCommand { get; set; }

        public DelegateCommand CancelCommand { get; set; }

        #endregion

        #region 属性

        public MemoInfoDTO MemoInfoDTO { get; set; }

        #endregion

        /// <summary>
        /// 构造函数
        /// </summary>
        public void OnDialogOpening(IDialogParameters parameters)
        {
            CancelCommand = new DelegateCommand(CancelFuc);
            SaveCommand = new DelegateCommand(SaveFunc);
            MemoInfoDTO = new MemoInfoDTO();
        }

        #region 具体方法实现

        /// <summary>
        /// 保存信息并回传
        /// </summary>
        private void SaveFunc()
        {
            if (MemoInfoDTO.Title == null || MemoInfoDTO.Content == null || MemoInfoDTO.Status == null)
            {
                MessageBox.Show("请完全输入内容！");
                return;
            }

            if (DialogHost.IsDialogOpen("RootDialog"))
            {
                DialogParameters param = new DialogParameters
                {
                    {"AddMemoInfo",MemoInfoDTO }
                };

                DialogHost.Close("RootDialog", new DialogResult(ButtonResult.OK, param));//回传数据
            }
        }


        /// <summary>
        /// 取消添加事项弹窗
        /// </summary>
        private void CancelFuc()
        {
            //整个 DialogHost 系统采用 容器托管模式。当你在主界面定义 Identifier="RootDialog" 时，实际上创建了一个全局对话框容器，所有在该容器内打开的对话框都共享这个宿主。
            //判断xx容器当前是否正在显示对话框层
            if (DialogHost.IsDialogOpen("RootDialog"))
            {
                DialogHost.Close("RootDialog", new DialogResult(ButtonResult.No));
            };
        }

        #endregion  
    }
}
